package com.albaba.designpattern.strategy.text_003;

import com.albaba.designpattern.strategy.text_002.Receipt;
import com.albaba.designpattern.strategy.text_002.ReceiptBuilder;

import java.util.List;

/**
 * @Description: TODO
 * @Author zx
 * @Date 2025/2/24 18:18
 * @Version 1.0
 */
public class Client {

    public static void main(String[] args) {


        // 模拟回执
        List<Receipt> receiptList = ReceiptBuilder.getReceiptList();

        // 策略上下文策略
        ReceiptContext context = new ReceiptContext();

        // 策略模式最主要的工作：将策略的定义，创建，使用这三部分进行了解耦
        for (Receipt receipt : receiptList) {
            // 获取策略
            ReceiptHandleStrategyFactory.init();
            ReceiptHandleStrategy receiptHandleStrategy = ReceiptHandleStrategyFactory.getStrategy(receipt.getType());
            // 设置策略
            context.setReceiptHandleStrategy(receiptHandleStrategy);
            // 调用策略
            context.handleReceipt(receipt);
        }

    }
}
